/*
 * @Author: C.
 * @Date: 2023-02-03 09:11:32
 */
import { downFile } from '/@/api/work/system/file';
import { downloadByData } from '/@/utils/file/download';
import { dataURLtoBlob } from '/@/utils/file/base64Conver';
import { openWindow } from '/@/utils';
// import { getAPIAd } from '../system';
export async function downloadByUrl({
  fileName,
  params = {},
}: {
  fileName: string;
  params?: object;
}) {
  const res = await downFile(params);
  downloadByData(res.data, fileName);
}

export async function blob2file(blob: Blob, fileName, fileType) {
  return new window.File([blob], fileName, { type: fileType });
}

export async function base64Tofile(base, fileName) {
  const blob = dataURLtoBlob(base);
  return new window.File([blob], fileName, { type: blob.type });
}

export function isImage(format: string) {
  const imgFormat: string[] = ['.png', '.jpg', '.webp', '.gif', '.jpeg'];
  return imgFormat.includes(format.toLowerCase());
}
export function isPDF(format: string) {
  const imgFormat: string[] = ['.pdf'];
  return imgFormat.includes(format.toLowerCase());
}
export function viewPDF(path: string) {
  // const url = getAPIAd() + path;
  openWindow(path);
}
